package com.jinhongone.pattern.behavior.state.before;

/**
 * @author jinho
 * @className Lift
 * @description 具体电梯
 * @date 2025/4/16 14:12
 */
public class Lift implements ILift {

    private int state;

    @Override
    public void setState(int state) {
        this.state = state;
    }

    @Override
    public void open() {
        switch (state) {
            case OPENING_STATE:
                break;
            case CLOSING_STATE:
            case STOPPING_STATE:
                System.out.println("电梯门已打开");
                setState(OPENING_STATE);
                break;
            case RUNNING_STATE:
                System.out.println("电梯运行中不能打开门");
                break;
        }
    }

    @Override
    public void close() {
        switch (state) {
            case OPENING_STATE:
                System.out.println("电梯门已关");
                setState(CLOSING_STATE);
                break;
            case CLOSING_STATE:
            case RUNNING_STATE:
            case STOPPING_STATE:
                break;
        }
    }

    @Override
    public void run() {
        switch (state) {
            case OPENING_STATE:
                System.out.println("电梯开门中，不能运行");
                break;
            case RUNNING_STATE:
                break;
            case CLOSING_STATE:
            case STOPPING_STATE:
                System.out.println("电梯开始运行");
                setState(RUNNING_STATE);
                break;
        }
    }

    @Override
    public void stop() {
        switch (state) {
            case OPENING_STATE:
            case STOPPING_STATE:
                break;
            case CLOSING_STATE:
            case RUNNING_STATE:
                System.out.println("电梯已停止");
                setState(STOPPING_STATE);
                break;

        }
    }
}
